import {
	objDeepCopy
} from "@/assets/js/common.js";
let Controller = {
	methods: {
		init() {
			this.getgoodsAttributelist(this);
			this.getStyleName(this);
			this.getTagsName(this);
			this.getOtherSlect(this, 'C06');
			this.getOtherSlect(this, 'C07');
			this.getcateg(this);
		},
		//组装分页
		paginationFunction(that, obj) {
			that.Model.paginationObject.currentPage = obj.pageIndex; // 第几页
			that.Model.paginationObject.pageSize = obj.pageSize; //  每页数量
			that.Model.paginationObject.pageTotal = obj.pageTotal; // 页总数
			that.Model.paginationObject.total = obj.total; //总数
			that.Model.paginationObject.num1 = (obj.pageIndex - 1) * obj.pageSize + 1 //num1
			//num2
			if (obj.pageTotal == obj.pageIndex) {
				that.Model.paginationObject.num2 = obj.total;
			} else {
				that.Model.paginationObject.num2 = obj.pageIndex * obj.pageSize;
			}
		},
		//获取列表数据
		getgoodsAttributelist(that, pageIndex, pageSize, searchObj) {
			searchObj = searchObj || {};
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/sale/saleGoodsMaster/goodsAttributelist',
				// url:'/api/sale/saleGoodsMaster/goodsAttributelist',
				data: {
					condition: searchObj,
					pageIndex: pageIndex,
					pageSize: pageSize
				}
			}).then((res) => {
				console.log(res);
				that.Model.tableData = [];
				var data = res.data;
				if (data.status == 200) {
					that.paginationFunction(that, data.result)
					var result = data.result.result;
					var obj = {};
					for (var i = 0; i < result.length; i++) {
						obj = objDeepCopy(result[i]);
						obj.isThereAQualityInspection == 1 ? obj.isThereAQualityInspection = '是' : obj.isThereAQualityInspection = '否';
						obj.maintenanceOrNot == 1 ? obj.maintenanceOrNot = '是' : obj.maintenanceOrNot = '否'
						obj.isCombinationGoods == 1 ? obj.isCombinationGoods = '是' : obj.isCombinationGoods = '否'
						obj.isCustomized == 1 ? obj.isCustomized = '是' : obj.isCustomized = '否'
						obj.isLettering == 1 ? obj.isLettering = '是' : obj.isLettering = '否'
						obj.isItWellMatched == 1 ? obj.isItWellMatched = '是' : obj.isItWellMatched = '否'
						obj.isThereAVersion == 1 ? obj.isThereAVersion = '是' : obj.isThereAVersion = '否'
						that.Model.tableData.push(obj);
					}

				} else {

				}
			});
		},

		//
		//获取 款式名称 下拉框
		getStyleName(that, prams) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsStyle/findlist',
				url: apiTest + '/sale/saleGoodsStyle/findlist',
				data: prams
			}).then((res) => {
				console.log(res);

				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].modelName,
							value: result[i].modelNo,
						}
						arr.push(obj);
						that.Model.filterOption.items[7].data = objDeepCopy(arr);
						that.Model.styleName = objDeepCopy(arr);
					}
				} else {

				}

			});
		},
		//获取 标签 下拉框
		getTagsName(that) {
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				// url:'/api/base/systemTagGroup/getTagGrouplist',
				url: apiTest + '/base/systemTagGroup/getTagGrouplist',
				data: {
					systemTagCategoryId: 2
				}
			}).then((res) => {
				console.log(res);
				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].name,
							value: result[i].id,
						}
						arr.push(obj);
						that.Model.filterOption.items[5].data = objDeepCopy(arr);
						that.Model.tagsName = objDeepCopy(arr);
					}
				} else {

				}

			});
		},
		//获取 销售分类 ，商品类型 下拉框
		getOtherSlect(that, type) {
			// type:C06 销售分类,type:C07 商品类型是
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsAttribute/getGoodsAttributelist',
				url: apiTest + '/sale/saleGoodsAttribute/getGoodsAttributelist',
				data: {
					attributeCode: type
				}
			}).then((res) => {
				console.log(res);
				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].propertyValueName,
							value: result[i].attributeValueCode,
						}
						arr.push(obj);

					}
					if (type == 'C06') {
						that.Model.salesClass = objDeepCopy(arr);
						that.Model.filterOption.items[2].data = objDeepCopy(arr);
					} else if (type == 'C07') {
						that.Model.commodityType = objDeepCopy(arr);
						that.Model.filterOption.items[3].data = objDeepCopy(arr);
					}


				} else {

				}

			});
		},
		//获取 品类 下拉框
		getcateg(that, prams) {
			var apiTest = this.apiTest;
			prams = prams || {}
			this.$ajax({
				method: 'post',
				// url:'/api/sale/saleGoodsLevel/list',
				url: apiTest + '/sale/saleGoodsLevel/list',
				data: {
					"level": 30
				}
			}).then((res) => {
				console.log(res);
				var data = res.data;
				if (data.status == 200) {
					var arr = [];
					var result = data.result.result;
					for (var i = 0; i < result.length; i++) {
						var obj = {
							label: result[i].goodsLevelName,
							value: result[i].goodsLevelCode,
						}
						arr.push(obj);
						that.Model.filterOption.items[4].data = objDeepCopy(arr);
						that.Model.categ = objDeepCopy(arr);
					}
				} else {

				}

			});
		},


		//点击进入修改tag页
		handleClickApproval(row) {
			this.$router.push({
				path: 'labelDetail',
				query: {
					'relId': row.id
				}
			});
		},
		//点击进入详情页
		showMore(row) {
			console.log(row.id)
			this.$router.push({
				path: 'attrListMsg',
				query: {
					'relId': row.id
				}
			})
		},
		handleSizeChange(val) {
			var searchObj = this.Model.searchObj;
			this.getgoodsAttributelist(this, 1, val, searchObj);
		},
		handleCurrentChange(val) {
			var searchObj = this.Model.searchObj;
			this.getgoodsAttributelist(this, val, undefined, searchObj);
		},
		// 
		showChild(val) {
			console.log(val);
			this.Model.searchObj = objDeepCopy(val);

		},
		toSearch(val) { //查询
			console.log(val);
			var searchObj = this.Model.searchObj;
			this.getgoodsAttributelist(this, 1, 10, searchObj);

		},
		toClear(val) {
			console.log(val);
			this.Model.searchObj = {}
			this.Model.filterOption.items[5].data = objDeepCopy(this.Model.tagsName);
			this.Model.filterOption.items[7].data = objDeepCopy(this.Model.styleName);
			this.Model.filterOption.items[2].data = objDeepCopy(this.Model.salesClass);
			this.Model.filterOption.items[3].data = objDeepCopy(this.Model.commodityType);
			this.Model.filterOption.items[4].data = objDeepCopy(this.Model.categ)
		},
		toExport(val) {
			console.log(val);
		},
		getNewHeaderData(newData) {
			this.Model.tableHeaderData = newData;
			console.log(this.Model.tableHeaderData)
		}
	},
	watch: {
		//
		$route: {
			handler(newValue, oldValue) {
				if (newValue.query.form == 'child') {
					this.init();
				}
			},
			deep: true
		},

	}
}
export default Controller;
